package com.sca.dealf.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.sca.dealf.entity.CommonResult;
import com.sca.dealf.entity.Product;
import com.sca.dealf.sentinelhandle.CustomerblockHandler;
import com.sca.dealf.sentinelhandle.ParamFlowHandler;
import com.sca.dealf.service.DealfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DealFController {

    @Autowired
    @Qualifier(value = "dealfService")
    private DealfService dealfService;


    @SentinelResource(value = "dealff"/*, blockHandlerClass = CustomerblockHandler.class, blockHandler = "handleException"*/)
    @GetMapping("/dealf/get/{id}")
    public CommonResult<Product> getPaymentById(@PathVariable("id") Long id ) {
        return dealfService.getPaymentById(id);
    }

    @SentinelResource(value = "dealff_slow"/*, blockHandlerClass = CustomerblockHandler.class, blockHandler = "handleException"*/)
    @GetMapping("/dealf/slow/{id}")
    public CommonResult<Product> getSlowPaymentById(@PathVariable("id") Long id ) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return dealfService.getPaymentById(id);
    }

    @SentinelResource(value = "dealff_ParamFlow", blockHandlerClass = ParamFlowHandler.class, blockHandler = "handleException")
    @GetMapping("/dealf/paramflow/{id}")
    public CommonResult<Product> getParamFlowPaymentById(@PathVariable("id") Long id ) {

        return dealfService.getPaymentById(id);
    }
}
